package com.example.myapplication;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.Toast;
import androidx.annotation.Nullable;
import com.example.myapplication.activity.CollectionActivity;
import com.example.myapplication.adapter.SongListAdapter;
import com.example.myapplication.bean.Song;
import com.example.myapplication.listener.TestListener;
import com.google.android.material.bottomnavigation.BottomNavigationView;
import androidx.appcompat.app.AppCompatActivity;
import androidx.navigation.NavController;
import androidx.navigation.Navigation;
import androidx.navigation.ui.AppBarConfiguration;
import androidx.navigation.ui.NavigationUI;
import com.example.myapplication.databinding.ActivityMainBinding;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

public class MainActivity extends AppCompatActivity {

    private ActivityMainBinding binding;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

//        binding = ActivityMainBinding.inflate(getLayoutInflater());
//        setContentView(binding.getRoot());
        setContentView(R.layout.activity_main);

        List<Song> songs = new ArrayList<>();
        Song song = new Song();
        song.setTitle("nana");
        song.setLength("09:99");
        song.setSinger("ayatsuji");
        songs.add(song);

        Song song1 = new Song();
        song1.setTitle("nana2");
        song1.setLength("09:992");
        song1.setSinger("ayatsuji2");
        songs.add(song1);

        ListView listView = findViewById(R.id.songList);
        listView.setAdapter(new SongListAdapter(songs, this));
//        BottomNavigationView navView = findViewById(R.id.nav_view);
        // Passing each menu ID as a set of Ids because each
        // menu should be considered as top level destinations.
//        AppBarConfiguration appBarConfiguration = new AppBarConfiguration.Builder(
//                R.id.navigation_home, R.id.navigation_dashboard, R.id.navigation_notifications)
//                .build();
//        NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment_activity_main);
//        NavigationUI.setupActionBarWithNavController(this, navController, appBarConfiguration);
//        NavigationUI.setupWithNavController(binding.navView, navController);

        findViewById(R.id.playOrPause).setOnClickListener(view -> {
            view.setPressed(!view.isPressed());
            System.out.println("!!!!!!!!!!click=============");
            Toast.makeText(this, "hello", Toast.LENGTH_SHORT).show();

            // 启动其他活动，方法1
//            Intent intent = new Intent(this, CollectionActivity.class);
//            startActivity(intent);

            // 启动其他活动，方法2
//            Intent intent = new Intent(Intent.ACTION_CALL);
//            intent.addCategory("com.example.myapplication.MyCategory");
//            startActivity(intent);

            // 打开浏览器
//            Intent intent = new Intent(Intent.ACTION_VIEW);
//            intent.setData(Uri.parse("http://www.bilibili.com"));
//            startActivity(intent);

            // 打电话
//            Intent intent = new Intent(Intent.ACTION_DIAL);
//            intent.setData(Uri.parse("tel:10086"));
//            startActivity(intent);

            // 传递数据给启动的活动
//            Intent intent = new Intent("the action");
//            intent.putExtra("title", "god");
//            startActivity(intent);

            // 从启动的活动获取返回数据
            Intent intent = new Intent("the action");
            startActivityForResult(intent, 1);
        });

        Executors.newScheduledThreadPool(1).scheduleAtFixedRate(() -> {
            ProgressBar progressBar = (ProgressBar)findViewById(R.id.songProgress);
            progressBar.setProgress(progressBar.getProgress() + 5);
        }, 3, 5, TimeUnit.SECONDS);

    }

    // 获取返回的数据
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        switch (requestCode) {
            case 1:
                if (resultCode == RESULT_OK) {
                    String resultData = data.getStringExtra("result");
                    Log.i(getClass().getName(), resultData);
                }
        }
        super.onActivityResult(requestCode, resultCode, data);
    }
}